package com.myspring.web.route;

import com.myspring.web.route.domain.LoanRequest;
import com.myspring.web.route.domain.LoanResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2017/5/17.
 *参考资料：
 *  使用Spring框架和AOP实现动态路由：http://www.infoq.com/cn/articles/dynamic-routing-using-spring
 *
 * 根据请求编码路由到某个service
 */
@Controller
@RequestMapping("/channel")
public class RouteController {
    private ChannelService channelService;

    /**
     * 贷款申请
     * @param loanRequest
     * @return
     */
    @RequestMapping(value = "/loan", method = RequestMethod.POST)
    @ResponseBody
    public LoanResponse loan(@RequestBody  LoanRequest loanRequest) {
        //dispatch分发code
        String bankCode = loanRequest.getBankCode();

        LoanResponse resp = new LoanResponse();
        resp.setLoanNo("9097");

        //参数校验
        channelService.load(loanRequest);

        //webservice远程调用银行服务，可以缓存service，参考creditcheck/AbstractRemoteProxy
        return resp;
    }

    /**
     * 还款
     */
    public void pay() {

    }

    /**
     * 提前还款
     */
    public void prepay() {

    }

    @ModelAttribute
    public void channelServiceList() {
        //获取容器中的所有服务
    }

    @InitBinder
    public void initBinder() {

    }

    /**
     * 拦截器动态注入
     * @param channelService
     */
    public void setChannelService(ChannelService channelService) {
        this.channelService = channelService;
    }
}
